package com.aretias.jkholdings.repository;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import com.aretias.jkholdings.model.Board;
import com.aretias.jkholdings.model.BoardParam;
import com.aretias.jkholdings.model.BoardReply;
import com.aretias.jkholdings.model.BoardReplyParam;

@Repository
public class BoardRepositoryImpl implements BoardRepository{
	
	private static final String NAMESPACE = "aretias.jkholding.board.";
	
	@Autowired
	private SqlMapClientTemplate client;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Board> selectBoardList(BoardParam param) {
		param.setLimitParam();
		return client.queryForList(NAMESPACE+"selectBoardList", param);
	}

	@Override
	public int insertBoard(BoardParam param) {
		Integer boardId = (Integer) client.insert(NAMESPACE+"insertBoard", param);
		return boardId;
	}

	@Override
	public void updateBoard(BoardParam param) {
		client.update(NAMESPACE+"updateBoard", param);		
	}

	@Override
	public Board selectBoard(BoardParam param) {
		return (Board)client.queryForObject(NAMESPACE+"selectBoard", param);
	}
	
	@Override
	public void deleteBoard(BoardParam param) {
		client.delete(NAMESPACE+"deleteBoard", param);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<BoardReply> selectBoardReplyList(BoardReplyParam param){
		return client.queryForList( NAMESPACE + "selectBoardReplyList", param);
	}
	
	@Override
	public BoardReply selectBoardReply(BoardReplyParam param){
		return (BoardReply) client.queryForObject( NAMESPACE + "selectBoardReplyList", param);
	}
	
	@Override
	public void insertBoardReply(BoardReplyParam param){
		client.insert(NAMESPACE + "insertBoardReply", param);
	}
	
	@Override
	public void updateBoardReply(BoardReplyParam param){
		client.update(NAMESPACE + "updateBoardReply", param);
	}
	
	@Override
	public void deleteBoardReply(BoardReplyParam param){
		client.delete(NAMESPACE + "deleteBoardReply", param);
	}
	
	@Override
	public int selectBoardListCount(BoardParam param){
		return (Integer) client.queryForObject(NAMESPACE + "selectBoardListCount", param);
	}
	
	@Override
	public int selectBoardReplyListCount(BoardReplyParam param){
		return (Integer) client.queryForObject(NAMESPACE + "selectBoardReplyListCount", param);
	}
}
